package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.config.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author zhaolingqiao
 * @CreateTime 2024/12/9
 * 定义SpringMVC配置类
 */
@Configuration
public class SpringMVCConfiguration implements WebMvcConfigurer {

    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 注册枚举类型转换器工厂
     * @param registry
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }

    /**
     * 注册拦截器，设置拦截地址、放行地址
     * 放行登录，获取验证码接口
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login/**");//放行登录，获取验证码接口
    }
}
